package com.dj.shop.service.impl;

import com.dj.shop.mapper.BrandMapper;
import com.dj.shop.mapper.ManuMapper;
import com.dj.shop.model.Brand;
import com.dj.shop.model.Manu;
import com.dj.shop.service.ManuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author renshp
 * @Title: ManuServiceImpl
 * @Description: TODO
 * @date 2019/3/1
 */
@Service
public class ManuServiceImpl implements ManuService {

    @Autowired
    ManuMapper manuMapper;

    @Autowired
    BrandMapper brandMapper;

    @Override
    public int addManu(Manu manu) {

        manu.setManuStatus("1");    // 默认为1-正常

        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        manu.setCreateDate(sdf.format(dt));
        manu.setUpdateDate(sdf.format(dt));
        sdf = new SimpleDateFormat("HHmmss");
        manu.setCreateTime(sdf.format(dt));
        manu.setUpdateTime(sdf.format(dt));

        return manuMapper.insert(manu);
    }

    @Override
    public int updateManu(Manu manu) {

        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        manu.setUpdateDate(sdf.format(dt));
        sdf = new SimpleDateFormat("HHmmss");
        manu.setUpdateTime(sdf.format(dt));

        return manuMapper.updateByPrimaryKeySelective(manu);
    }

    @Override
    public int updateManuStatus(int manuId, String manuStatus) {

        Manu manu = new Manu();

        manu.setManuId(manuId);
        manu.setManuStatus(manuStatus);
        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        manu.setUpdateDate(sdf.format(dt));
        sdf = new SimpleDateFormat("HHmmss");
        manu.setUpdateTime(sdf.format(dt));

        return manuMapper.updateByPrimaryKeySelective(manu);
    }

    @Override
    public Manu queryManuById(int manuId) {
        return manuMapper.selectByPrimaryKey(manuId);
    }

    @Override
    public int addBrand(Brand brand) {
        brand.setBrandStatus("1");    // 默认为1-正常

        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        brand.setCreateDate(sdf.format(dt));
        brand.setUpdateDate(sdf.format(dt));
        sdf = new SimpleDateFormat("HHmmss");
        brand.setCreateTime(sdf.format(dt));
        brand.setUpdateTime(sdf.format(dt));

        return brandMapper.insert(brand);
    }

    @Override
    public int updateBrand(Brand brand) {

        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        brand.setUpdateDate(sdf.format(dt));
        sdf = new SimpleDateFormat("HHmmss");
        brand.setUpdateTime(sdf.format(dt));

        return brandMapper.updateByPrimaryKeySelective(brand);

    }

    @Override
    public int updateBrandStatus(int brandId, String brandStatus) {

        Brand brand = new Brand();

        brand.setManuId(brandId);
        brand.setBrandStatus(brandStatus);
        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        brand.setUpdateDate(sdf.format(dt));
        sdf = new SimpleDateFormat("HHmmss");
        brand.setUpdateTime(sdf.format(dt));

        return brandMapper.updateByPrimaryKeySelective(brand);

    }

    @Override
    public Brand queryBrandById(int brandId) {
        return brandMapper.selectByPrimaryKey(brandId);
    }

    @Override
    public List<Brand> queryBrandsByManuId(int manuId) {
        return brandMapper.selectBrandsByManuId(Integer.valueOf(manuId));
    }
}
